package Servlet;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

import Dao.UserDao;

public class DeleteUser {

	public void delete(int id, String JDBC_URL, String JDBC_USER, String JDBC_PASSWORD) throws Exception{
		Connection con = null;
		PreparedStatement ps = null;
		try {
			Class.forName("com.mysql.cj.jdbc.Driver");
			con = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWORD);
			ps = con.prepareStatement("delete from users where id=?");
			ps.setInt(1, id);
			ps.executeUpdate();
		}catch(Exception e){
			throw new Exception("DAO异常:" + e.getMessage());
		}finally {
			if(ps != null) {
				ps.close();
			}
			if(con != null) {
				con.close();
			}
		}
	}
	public static void main(String[] args) {
		UserDao userDAO = new UserDao();
		try {
			userDAO.delete(1);
		}catch(Exception e) {
			e.printStackTrace();
		}
	}
}
